import * as THREE from 'three';
import '../../css/base.css'

let scene, camera, renderer;
let cube;

function initScene() {
  scene = new THREE.Scene();
} // 初始化场景
function initCamera() {
  camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
  camera.position.z = 5;
} // 初始化相机
function initRenderer() {
  renderer = new THREE.WebGLRenderer();
  renderer.setSize(window.innerWidth, window.innerHeight);
  document.body.appendChild(renderer.domElement);
}// 初始化加载器
function initModel() {
  let geometry = new THREE.BoxGeometry();
  let material = new THREE.MeshBasicMaterial({color: 0x00ff00});
  cube = new THREE.Mesh(geometry, material);
  scene.add(cube);
}// 初始化模型
function render() {
  cube.rotation.x += 0.01;
  cube.rotation.y += 0.01;
  renderer.render(scene, camera);
}// 渲染
function animate() {
  requestAnimationFrame(animate);
  render();
}// 动画
(function main() {
  initScene();
  initCamera();
  initRenderer();
  initModel();
  animate();
})() // 运行
